<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta name="Content-Type" content="text/html; charset=UTF-8" />
<title>Class: Sass::Tree::Visitors::ToCss</title>
<link rel="stylesheet" href="style.css" tppabs="http://sass-lang.com/docs/yardoc/css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="common.css" tppabs="http://sass-lang.com/docs/yardoc/css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '../../..';
  if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="jquery.js" tppabs="http://sass-lang.com/docs/yardoc/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="app.js" tppabs="http://sass-lang.com/docs/yardoc/js/app.js"></script>

  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="_index.html" tppabs="http://sass-lang.com/docs/yardoc/_index.html">Index (T)</a> &raquo; 
    <span class='title'><a href="Sass-1.html" tppabs="http://sass-lang.com/docs/yardoc/Sass.html" title="Sass (module)">Sass</a></span> &raquo; <span class='title'><a href="Tree.html" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree.html" title="Sass::Tree (module)">Tree</a></span> &raquo; <span class='title'><a href="Visitors.html" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors.html" title="Sass::Tree::Visitors (module)">Visitors</a></span>
     &raquo; 
    <span class="title">ToCss</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="javascript:if(confirm(%27http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/.  \n\nThis file was not retrieved by Teleport Pro, because the server reports that this file cannot be found.  \n\nDo you want to open it from the server?%27))window.location=%27http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/.%27" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  <a id="class_list_link" href="#">Class List</a>
  <a id="method_list_link" href="#">Method List</a>
  <a id ="file_list_link" href="#">File List</a>
</div>

      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Class: Sass::Tree::Visitors::ToCss 
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName"><a href="Base.html" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html" title="Sass::Tree::Visitors::Base (class)">Base</a></span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next"><a href="Base.html" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html" title="Sass::Tree::Visitors::Base (class)">Base</a></li>
          
            <li class="next">Sass::Tree::Visitors::ToCss</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>A visitor for converting a Sass tree into CSS.</p>

  </div>
</div>
<div class="tags">
  
</div>
  <h2>Constant Summary</h2>
  


  
  
  
  

  <h2>Instance Method Summary</h2>

  <ul class="summary">
    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#initialize-instance_method" title="#initialize (instance method)">- (ToCss) <strong>initialize</strong> </a>
    

    
  </span>
  
    <span class="note title constructor">constructor</span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc">A new instance of ToCss.</span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit-instance_method" title="#visit (instance method)">- <strong>visit</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_charset-instance_method" title="#visit_charset (instance method)">- <strong>visit_charset</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_comment-instance_method" title="#visit_comment (instance method)">- <strong>visit_comment</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_cssimport-instance_method" title="#visit_cssimport (instance method)">- <strong>visit_cssimport</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_directive-instance_method" title="#visit_directive (instance method)">- <strong>visit_directive</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_media-instance_method" title="#visit_media (instance method)">- <strong>visit_media</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_prop-instance_method" title="#visit_prop (instance method)">- <strong>visit_prop</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_root-instance_method" title="#visit_root (instance method)">- <strong>visit_root</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_rule-instance_method" title="#visit_rule (instance method)">- <strong>visit_rule</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#visit_supports-instance_method" title="#visit_supports (instance method)">- <strong>visit_supports</strong>(node) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="protected ">
  <span class="summary_signature">
    
      <a href="#with_tabs-instance_method" title="#with_tabs (instance method)">- <strong>with_tabs</strong>(tabs) </a>
    

    
  </span>
  
  
  <span class="note title protected">protected</span>
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
  </ul>

  
  
  
  
  
  <h3 class="inherited">Methods inherited from <a href="Base.html" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html" title="Sass::Tree::Visitors::Base (class)">Base</a></h3>
  <p class="inherited"><a href="Base.html#node_name-instance_method" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html#node_name-instance_method" title="Sass::Tree::Visitors::Base#node_name (method)">#node_name</a>, <a href="Base.html#visit-class_method" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html#visit-class_method" title="Sass::Tree::Visitors::Base.visit (method)">visit</a>, <a href="Base.html#visit_children-instance_method" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html#visit_children-instance_method" title="Sass::Tree::Visitors::Base#visit_children (method)">#visit_children</a>, <a href="Base.html#visit_if-instance_method" tppabs="http://sass-lang.com/docs/yardoc/Sass/Tree/Visitors/Base.html#visit_if-instance_method" title="Sass::Tree::Visitors::Base#visit_if (method)">#visit_if</a></p>
<div id="constructor_details" class="method_details_list">
  <h2>Constructor Details</h2>
  
    <div class="method_details first">
  <p class="signature first" id="initialize-instance_method">
  
    - (<tt><a href="" title="Sass::Tree::Visitors::ToCss (class)">ToCss</a></tt>) <strong>initialize</strong>  <span class="extras">(protected)</span>
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>A new instance of ToCss</p>

  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


5
6
7</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 5</span>

def initialize
  @tabs = 0
end</pre>
    </td>
  </tr>
</table>
</div>
  
</div>


  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="visit-instance_method">
  
    - <strong>visit</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


9
10
11
12
13
14</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 9</span>

def visit(node)
  super
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => node.filename, :line => node.line)
  raise e
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_charset-instance_method">
  
    - <strong>visit_charset</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


54
55
56</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 54</span>

def visit_charset(node)
  "@charset \"#{node.name}\";"
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_comment-instance_method">
  
    - <strong>visit_comment</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


58
59
60
61
62
63
64
65
66</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 58</span>

def visit_comment(node)
  return if node.invisible?
  spaces = ('  ' * [@tabs - node.resolved_value[/^ */].size, 0].max)

  content = node.resolved_value.gsub(/^/, spaces)
  content.gsub!(%r{^(\s*)//(.*)$}) {|md| "#{$1}/*#{$2} */"} if node.type == :silent
  content.gsub!(/\n +(\* *(?!\/))?/, ' ') if (node.style == :compact || node.style == :compressed) && node.type != :loud
  content
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_cssimport-instance_method">
  
    - <strong>visit_cssimport</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


120
121
122</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 120</span>

def visit_cssimport(node)
  visit_directive(node)
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_directive-instance_method">
  
    - <strong>visit_directive</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 68</span>

def visit_directive(node)
  was_in_directive = @in_directive
  tab_str = '  ' * @tabs
  return tab_str + node.resolved_value + ";" unless node.has_children
  return tab_str + node.resolved_value + " {}" if node.children.empty?
  @in_directive = @in_directive || !node.is_a?(Sass::Tree::MediaNode)
  result = if node.style == :compressed
             "#{node.resolved_value}{"
           else
             "#{tab_str}#{node.resolved_value} {" + (node.style == :compact ? ' ' : "\n")
           end
  was_prop = false
  first = true
  node.children.each do |child|
    next if child.invisible?
    if node.style == :compact
      if child.is_a?(Sass::Tree::PropNode)
        with_tabs(first || was_prop ? 0 : @tabs + 1) {result << visit(child) << ' '}
      else
        result[-1] = "\n" if was_prop
        rendered = with_tabs(@tabs + 1) {visit(child).dup}
        rendered = rendered.lstrip if first
        result << rendered.rstrip + "\n"
      end
      was_prop = child.is_a?(Sass::Tree::PropNode)
      first = false
    elsif node.style == :compressed
      result << (was_prop ? ";" : "") << with_tabs(0) {visit(child)}
      was_prop = child.is_a?(Sass::Tree::PropNode)
    else
      result << with_tabs(@tabs + 1) {visit(child)} + "\n"
    end
  end
  result.rstrip + if node.style == :compressed
                    "}"
                  else
                    (node.style == :expanded ? "\n" : " ") + "}\n"
                  end
ensure
  @in_directive = was_in_directive
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_media-instance_method">
  
    - <strong>visit_media</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


110
111
112
113
114</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 110</span>

def visit_media(node)
  str = with_tabs(@tabs + node.tabs) {visit_directive(node)}
  str.gsub!(/\n\Z/, '') unless node.style == :compressed || node.group_end
  str
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_prop-instance_method">
  
    - <strong>visit_prop</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


124
125
126
127
128
129
130
131
132</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 124</span>

def visit_prop(node)
  return if node.resolved_value.empty?
  tab_str = '  ' * (@tabs + node.tabs)
  if node.style == :compressed
    "#{tab_str}#{node.resolved_name}:#{node.resolved_value}"
  else
    "#{tab_str}#{node.resolved_name}: #{node.resolved_value};"
  end
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_root-instance_method">
  
    - <strong>visit_root</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 23</span>

def visit_root(node)
  result = String.new
  node.children.each do |child|
    next if child.invisible?
    child_str = visit(child)
    result << child_str + (node.style == :compressed ? '' : "\n")
  end
  result.rstrip!
  return "" if result.empty?
  result << "\n"
  unless Sass::Util.ruby1_8? || result.ascii_only?
    if node.children.first.is_a?(Sass::Tree::CharsetNode)
      begin
        encoding = node.children.first.name
        # Default to big-endian encoding, because we have to decide somehow
        encoding << 'BE' if encoding =~ /\Autf-(16|32)\Z/i
        result = result.encode(Encoding.find(encoding))
      rescue EncodingError
      end
    end

    result = "@charset \"#{result.encoding.name}\";#{
      node.style == :compressed ? '' : "\n"
    }".encode(result.encoding) + result
  end
  result
rescue Sass::SyntaxError => e
  e.sass_template ||= node.template
  raise e
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_rule-instance_method">
  
    - <strong>visit_rule</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 134</span>

def visit_rule(node)
  with_tabs(@tabs + node.tabs) do
    rule_separator = node.style == :compressed ? ',' : ', '
    line_separator =
      case node.style
        when :nested, :expanded; "\n"
        when :compressed; ""
        else; " "
      end
    rule_indent = '  ' * @tabs
    per_rule_indent, total_indent = [:nested, :expanded].include?(node.style) ? [rule_indent, ''] : ['', rule_indent]

    joined_rules = node.resolved_rules.members.map do |seq|
      next if seq.has_placeholder?
      rule_part = seq.to_a.join
      if node.style == :compressed
        rule_part.gsub!(/([^,])\s*\n\s*/m, '\1 ')
        rule_part.gsub!(/\s*([,+>])\s*/m, '\1')
        rule_part.strip!
      end
      rule_part
    end.compact.join(rule_separator)

    joined_rules.sub!(/\A\s*/, per_rule_indent)
    joined_rules.gsub!(/\s*\n\s*/, "#{line_separator}#{per_rule_indent}")
    total_rule = total_indent << joined_rules

    to_return = ''
    old_spaces = '  ' * @tabs
    spaces = '  ' * (@tabs + 1)
    if node.style != :compressed
      if node.options[:debug_info] && !@in_directive
        to_return << visit(debug_info_rule(node.debug_info, node.options)) << "\n"
      elsif node.options[:trace_selectors]
        to_return << "#{old_spaces}/* "
        to_return << node.stack_trace.join("\n   #{old_spaces}")
        to_return << " */\n"
      elsif node.options[:line_comments]
        to_return << "#{old_spaces}/* line #{node.line}"

        if node.filename
          relative_filename = if node.options[:css_filename]
            begin
              Pathname.new(node.filename).relative_path_from(
                Pathname.new(File.dirname(node.options[:css_filename]))).to_s
            rescue ArgumentError
              nil
            end
          end
          relative_filename ||= node.filename
          to_return << ", #{relative_filename}"
        end

        to_return << " */\n"
      end
    end

    if node.style == :compact
      properties = with_tabs(0) {node.children.map {|a| visit(a)}.join(' ')}
      to_return << "#{total_rule} { #{properties} }#{"\n" if node.group_end}"
    elsif node.style == :compressed
      properties = with_tabs(0) {node.children.map {|a| visit(a)}.join(';')}
      to_return << "#{total_rule}{#{properties}}"
    else
      properties = with_tabs(@tabs + 1) {node.children.map {|a| visit(a)}.join("\n")}
      end_props = (node.style == :expanded ? "\n" + old_spaces : ' ')
      to_return << "#{total_rule} {\n#{properties}#{end_props}}#{"\n" if node.group_end}"
    end

    to_return
  end
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="visit_supports-instance_method">
  
    - <strong>visit_supports</strong>(node)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


116
117
118</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 116</span>

def visit_supports(node)
  visit_media(node)
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="with_tabs-instance_method">
  
    - <strong>with_tabs</strong>(tabs)  <span class="extras">(protected)</span>
  

  
</p><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


16
17
18
19
20
21</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/tree/visitors/to_css.rb', line 16</span>

def with_tabs(tabs)
  old_tabs, @tabs = @tabs, tabs
  yield
ensure
  @tabs = old_tabs
end</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Fri Mar  8 20:34:04 2013 by 
  <a href="javascript:if(confirm(%27http://yardoc.org/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://yardoc.org/%27" tppabs="http://yardoc.org/" title="Yay! A Ruby Documentation Tool">yard</a>
  0.5.3 (ruby-1.8.7).
</div>


  <script type="text/javascript">
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  </script>
  <script type="text/javascript">
  try {
  var pageTracker = _gat._getTracker("UA-535380-8");
  pageTracker._trackPageview();
  } catch(err) {}</script>


  </body>
</html>